package com.xckj.bigdata.demo.controller;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 刘嘉民 on 2020/6/17 15:17
 */
public class LeetCode {
    public static void main(String[] args) {
//        int[] nums ={0,0,1,1,1,2,2,3,3,4};
////        int a = nums[0];
////        int b = 1;
////        for (int i = 1; i < nums.length; i++) {
////            if (nums[i]==a){
////
////            }else{
////                a=nums[i];
////                nums[b]=nums[i];
////                b++;
////            }
////        }
//        int[] nums ={0,1,2,2,3,0,4,2};
//
//        int a=removeElement(nums,2);
//        System.out.println(a);
//        System.out.println(searchInsert(nums,0));
//        System.out.println(mySqrt(4));

//       String s = "abc";
//       Boolean bn = strDuplicate(s);
//        System.out.println(bn);
//        int[] candies={12,1,12};
//        kidsWithCandies(candies,10);
//      String  haystack = "aaa", needle = "a";
//       int index =  strStr(haystack,needle);
//        System.out.println(index);


        int [] arrays={1,2,3};
        List<List<Integer>> lists= permute(arrays);
        System.out.println(lists);
    }
    public static List<List<Integer>> permute(int[] nums) {
        List<List<Integer>> lists= new ArrayList<List<Integer>>();
        for (int i = 0; i < nums.length; i++) {
            for (int j = 0; j < nums.length; j++) {
                if (j!=i){
                    List<Integer> list = new ArrayList<Integer>();
//                    list = digui(list,);
                }
            }
        }
        return lists;
    }
    private static Boolean strDuplicate(String s) {
        char[] crs = s.toCharArray();
        for (int i = 0; i < crs.length - 1 ; i++) {
            for (int j = i + 1; j < crs.length; j++) {
                if (crs[i]==crs[j]){
                    return false;
                }
            }
        }
        return true;
    }

    public static int removeElement(int[] nums, int val) {
        int a=0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i]!=val){
                nums[a]=nums[i];
                a++;
            }
        }
            return a;
    }
    public static int removeDuplicates(int[] nums) {
        if (nums.length == 0) return 0;
        int i = 0;
        for (int j = 1; j < nums.length; j++) {
            if (nums[j] != nums[i]) {
                i++;
                nums[i] = nums[j];
            }
        }
        return i + 1;
    }

    public static int searchInsert(int[] nums, int target) {
        for (int i = 0; i < nums.length; i++) {
            if (target==nums[i]||nums[i]>target){
                return i;
            }
        }
        return nums.length;
    }
    public static int[] runningSum(int[] nums) {
        int [] nums1 = new int[nums.length];
        for (int i = 0; i < nums.length; i++) {
            int temp=0;
            for (int j = 0; j <= i; j++) {
                temp+=nums[j];
            }
            nums1[i]=temp;
        }
            return nums1;
    }
    public static int mySqrt(int x) {
        int i = 1;
        while (true){
            if (i*i==x){
               return i;
            }else if (i*i>x){
                return i-1;
            }
           i++;
        }
    }

    public static List<Boolean> kidsWithCandies(int[] candies, int extraCandies) {
        List<Boolean> list = new ArrayList<Boolean>();
        int max = 0;
        for (int i = 0; i < candies.length; i++) {
            if (candies[i]>max){
                max=candies[i];
            }
        }
        for (int i = 0; i < candies.length; i++) {
            if (candies[i]+extraCandies>=max){
                list.add(true);
            }else {
                list.add(false);
            }
        }
        return  list;
    }

    public static int strStr(String haystack, String needle) {
        if (haystack==null||haystack.equals("")){
            return 0;
        }
       String [] arrays= haystack.split(needle);
        if (arrays.length>1){
            return arrays[0].length();
        }else {
            return -1;
        }
    }

}
